package com.rtx.edi.platform.tableconfig.controller;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.edi.model.response.EdiResponse;
import com.rtx.edi.platform.tableconfig.bean.EdiColumnValueConfig;
import com.rtx.edi.platform.tableconfig.bean.EdiTableConfig;
import com.rtx.edi.platform.tableconfig.service.EdiColumnValueConfigService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@SuppressWarnings("all")
@Api(tags = {"字段配置"})
@RestController
@RequestMapping("/v1/ediColumnValueConfig")
public class EdiColumnValueConfigController {
	
	@Autowired
	EdiColumnValueConfigService ediColumnValueConfigService;
	
    @ApiOperation(value = "获取报文节点", notes = "初始化字段配置")
    @PostMapping("requestNodeSelect")
	public EdiResponse requestNodeSelect(@RequestBody EdiColumnValueConfig dto) {
    	List<Map<String, String>> list = ediColumnValueConfigService.requestNodeSelect(dto);
		return EdiResponse.success().data("item", list);
	}
	
    //弃用 不进行初始化
    @Deprecated
    @ApiOperation(value = "初始化字段配置", notes = "初始化字段配置")
    @PostMapping("initColumnsValueConfig")
    public EdiResponse initColumnsValueConfig(@RequestBody EdiColumnValueConfig dto){
    	ediColumnValueConfigService.initColumnsValueConfig(dto);
        return EdiResponse.success();
    }
    

    
    @ApiOperation(value = "查询当前字段配置", notes = "查询当前字段配置")
    @PostMapping("queryCurrentConfig")
    public EdiResponse queryCurrentConfig(@RequestBody EdiColumnValueConfig dto) {
    	return ediColumnValueConfigService.queryCurrentConfig(dto);
    }
    
    @ApiOperation(value = "保存当前字段配置", notes = "保存当前字段配置")
    @PostMapping("saveCurrentConfig")
    public EdiResponse saveCurrentConfig(@RequestBody String requestStr) {
    	return ediColumnValueConfigService.saveCurrentConfig(requestStr);
    }

    /**
     * 获取表配置
     * @return
     */
    @ApiOperation(value = "获取字段配置", notes = "分页获取字段配置")
    @PostMapping("selectColumnValueConfigList")
    public EdiResponse selectColumnValueConfigList(@RequestBody EdiColumnValueConfig dto){
        Page<EdiColumnValueConfig> pageParam = new Page<>(dto.getPageNum(), dto.getPageSize());
        ediColumnValueConfigService.selectList(pageParam,dto);
        return EdiResponse.success().data("page",pageParam);
    }
    
    /**
     * 查询表配置
     * @return
     */
    @ApiOperation(value = "查询字段配置", notes = "根据ID 字段配置")
    @PostMapping("selectColumnValueConfigById")
    public EdiResponse selectColumnValueConfigById(@RequestBody EdiColumnValueConfig dto){
        return EdiResponse.success().data("item",ediColumnValueConfigService.getById(dto.getId()));
    }

    /**
     * 新增表配置
     * @return
     */
    @ApiOperation(value = "新增字段配置", notes = "新增字段配置")
    @PostMapping("addEdiColumnValueConfig")
    public EdiResponse addEdiColumnValueConfig(@RequestBody EdiColumnValueConfig dto){
    	return ediColumnValueConfigService.addEdiColumnValueConfig(dto);
    }

    /**
     * 修改表配置
     * @return
     */
    @ApiOperation(value = "修改字段配置", notes = "根据字段配置")
    @PostMapping("editEdiColumnValueConfig")
    public EdiResponse editEdiColumnValueConfig(@RequestBody EdiColumnValueConfig dto){
    	return ediColumnValueConfigService.editEdiColumnValueConfig(dto);
    }
    
    /**
     * 批量删除Edi开放接口创建配置
     * @return
     */
    @ApiOperation(value = "批量删除 字段配置", notes = "批量删除 字段配置")
    @PostMapping("deleteEdiColumnValueConfig")
    public EdiResponse deleteEdiColumnValueConfigByIds(@RequestBody List<EdiColumnValueConfig> list){
    	return ediColumnValueConfigService.deleteEdiColumnValueConfigByIds(list);
    }

}
